/**
 * Copyright (C) 2013-2014 the original author or authors.
 */
package com.foreveross.bsl.common.utils.web.context;

import javax.servlet.ServletContextEvent;

import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.foreveross.bsl.common.utils.factory.InstanceFactory;
import com.foreveross.bsl.common.utils.factory.InstanceSpringProvider;


/**
 * @description
 *
 * @author rening
 * @version v1.0
 *
 * @2013-3-18
 *
 */
public class AppSpringContextLoaderListener extends ContextLoaderListener {

	/* (non-Javadoc)
	 * @see org.springframework.web.context.ContextLoaderListener#contextInitialized(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextInitialized(ServletContextEvent event) {
		super.contextInitialized(event);
		WebApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext());
		InstanceSpringProvider provider = new InstanceSpringProvider(applicationContext);
		InstanceFactory.setInstanceProvider(provider);
	}
}
